package com.xyh.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.xyh.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaoyh
 */
@Slf4j
@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserClient userClient;

    @Value("${server.port}")
    private String port;

    @Value("${bus.text}")
    private String text;

    @GetMapping("/list")
    @HystrixCommand(fallbackMethod = "fallbackLogin")
    public String list() {
        String login = userClient.login();
        log.info("login user: {}", login);
        return "order list ! server port: " + port + " spring cloud bus：" + text;
    }

    // 熔断器回调方法
    public String fallbackLogin() {
        return "User service is currently unavailable. Please try again later." + " spring cloud bus：" + text;
    }


}
